<div class="order_pannel">
    <div class="manage-account-form-wrapper">
        <p class="success" th:if="${successMessage}" th:text="${successMessage}"></p>
        <h2>收货地址管理</h2>
        <p th:if="${#lists.isEmpty(customerAddresses)}">
            您还未添加收货地址。请填写下表添加。
        </p>
        <div class="address_option" th:unless="${#lists.isEmpty(customerAddresses)}">
            选项:
            <select onchange="location.href=this.options[selectedIndex].value" style="width:180px">
                <option>选择地址更新...</option>
                <option th:each="customerAddress : ${customerAddresses}" th:object="${customerAddress}" th:value="@{'/account/addresses/' + *{id}}">
                    <span th:text="*{!#strings.isEmpty(addressName) ? addressName + ' (' + address.addressLine1 + ')' : address.addressLine1}"></span>
                </option>
            </select>
            <span th:if="${customerAddressForm.customerAddressId}">&nbsp;&nbsp;- 或 -&nbsp;&nbsp;<a th:href="@{/account/addresses}" class="medium red">新增地址</a></span>
            <span th:unless="${customerAddressForm.customerAddressId}">&nbsp;&nbsp;- 或 -&nbsp;&nbsp;填写下表新增地址</span>
        </div>
        <blc:form class="manage-account" method="post" th:action="@{'/account/addresses/' + ${customerAddressForm.customerAddressId != null ? customerAddressForm.customerAddressId : ''}}" th:object="${customerAddressForm}">
            <div>
                <div class="form30">
                    <label for="firstName">姓名</label>
                   
                    <input type="text" class="field30 required" th:field="*{address.firstName}" th:classappend="${#fields.hasErrors('address.firstName')}? 'fieldError'" />
                    <span class="error" th:if="${#fields.hasErrors('address.firstName')}" th:errors="*{address.firstName}"></span>
                </div>
                <!--
                <div class="form30">
                    <label for="idCard">身份证</label>
                    <input type="text" th:field="*{address.receiver.idCard}" class="field30 required cloneable" th:classappend="${#fields.hasErrors('address.receiver.idCard')}? 'fieldError'" />
                    <span class="error" th:if="${#fields.hasErrors('address.receiver.idCard')}" th:errors="*{address.receiver.idCard}"></span>
                </div>
                -->
                <div class="form30">
                    <label for="phone">手机号</label>
                   
                    <input type="tel" id="address.phonePrimary" name="address.phonePrimary" th:value="*{address.phonePrimary.phoneNumber}" class="field30 cloneable" />
                    <span class="error_spacer" th:if="${#fields.hasErrors('address.firstName') or #fields.hasErrors('address.lastName')}">错误</span>
                </div>
                <div class="form50 form_city">
                    <label for="city">省 / 市</label>
                    <select id="state" th:field="*{address.state}" size="1" style="width: 80px;" class="required cloneable" th:classappend="${#fields.hasErrors('address.state')}? 'fieldError'">
                        <option value="">--</option>
                        <option th:each="state : ${states}" th:value="${state.abbreviation}" th:text="${state.name}"></option>
                    </select>
                    <input type="text" th:field="*{address.city}" class="field30 required cloneable" th:classappend="${#fields.hasErrors('address.city')}? 'fieldError'" />
                    <span class="error" th:if="${#fields.hasErrors('address.city')}" th:errors="*{address.city}"></span>
                    <br th:if="${#fields.hasErrors('address.city')} and ${#fields.hasErrors('address.state')}" />
                    <span class="error" th:if="${#fields.hasErrors('address.state')}" th:errors="*{address.state}"></span>
                </div>
                <div class="form50">
                    <label for="address1">详细地址</label>        
                    <input type="text" th:field="*{address.addressLine1}" class="field50 required cloneable" th:classappend="${#fields.hasErrors('address.addressLine1')}? 'fieldError'" />
                    <span class="error" th:if="${#fields.hasErrors('address.addressLine1')}" th:errors="*{address.addressLine1}"></span>
                </div>            
                <div class="form25">
                    <label for="postal_code">邮政编码</label>
                    <span class="error" th:if="${#fields.hasErrors('address.postalCode')}" th:errors="*{address.postalCode}"></span>
                    <input type="text" th:field="*{address.postalCode}" class="field25 cloneable" th:classappend="${#fields.hasErrors('address.postalCode')}? 'fieldError'" />
                </div>
                <div class="form25 default">
                    <input id="def" type="checkbox" th:field="*{address.default}" class="field25" style="width:22px;" /> 
                    <label for="def">设为默认</label>
                </div>
                <input type="hidden" name="address.country" value="CN" />
                <div class="clearfix"></div>
            </div>
            <div class="add_ctrl">
                <input type="submit" id="address_submit" th:value="*{customerAddressId != null ? '更新地址' : '保存地址'}" class="medium red" />
                <input th:if="*{customerAddressId}" type="submit" name="removeAddress" th:value="#{address.remove}" class="small dark" />
                <span class="error" th:if="${errorMessage}" th:text="${errorMessage}"></span>
            </div>
        </blc:form>
    </div>
</div>
